package com.ruoyi.pad.controller;


import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.pad.domain.KyPadInfo;
import com.ruoyi.pad.service.IKyPadInfoService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 平板信息Controller
 *
 * @author 矿一
 * @date 2023-01-31
 */
@RestController
@RequestMapping("/KyPadInfo/pad")
public class KyPadInfoController extends BaseController {
    @Resource
    private IKyPadInfoService kyPadInfoService;

    /**
     * 查询平板信息列表
     */
    @PreAuthorize("@ss.hasPermi('platform:pad:list')")
    @GetMapping("/list")
    public TableDataInfo list(KyPadInfo kyPadInfo) {
        startPage();
        List<KyPadInfo> list = kyPadInfoService.selectKyPadInfoList(kyPadInfo);
        return getDataTable(list);
    }

    /**
     * 导出平板信息列表
     */
    @PreAuthorize("@ss.hasPermi('platform:pad:export')")
    @Log(title = "平板信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(KyPadInfo kyPadInfo) {
        List<KyPadInfo> list = kyPadInfoService.selectKyPadInfoList(kyPadInfo);
        ExcelUtil<KyPadInfo> util = new ExcelUtil<>(KyPadInfo.class);
        util.exportExcel(list, "平板信息数据");
    }

    /**
     * 获取平板信息详细信息
     */
    @PreAuthorize("@ss.hasPermi('platform:pad:query')")
    @GetMapping(value = "/{padId}")
    public AjaxResult getInfo(@PathVariable("padId") Long padId) {
        return success(kyPadInfoService.selectKyPadInfoByPadId(padId));
    }

    /**
     * 新增平板信息
     */
    @PreAuthorize("@ss.hasPermi('platform:pad:add')")
    @Log(title = "平板信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody KyPadInfo kyPadInfo) {
        return toAjax(kyPadInfoService.insertKyPadInfo(kyPadInfo));
    }

    /**
     * 修改平板信息
     */
    @PreAuthorize("@ss.hasPermi('platform:pad:edit')")
    @Log(title = "平板信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody KyPadInfo kyPadInfo) {
        return toAjax(kyPadInfoService.updateKyPadInfo(kyPadInfo));
    }

    /**
     * 删除平板信息
     */
    @PreAuthorize("@ss.hasPermi('platform:pad:remove')")
    @Log(title = "平板信息", businessType = BusinessType.DELETE)
    @DeleteMapping("/{padIds}")
    public AjaxResult remove(@PathVariable Long[] padIds) {
        return toAjax(kyPadInfoService.deleteKyPadInfoByPadIds(padIds));
    }
}
